<?php
namespace app\api\controller;
use app\api\logic\UserLogic;
class Crontab extends Base{
    public function index(){
        //更新二维码
        //删除二维码
        $path = ROOT_PATH . 'public/qrcode/sign_qrcode.png';
        unlink($path);
        //重新生成二维码
        $token_new = md5(mt_rand(1000, 9999) . time());
        $date = strtotime(date('Y-m-d',time()));
        $data = json_encode(array(
            'date' => $date,
            'token' => $token_new
        ));
        UserLogic::create_qrcode($data);
        //更新公益基金
        //公益基金
        //参与减肥人数
        $where['first_weight'] = array('gt',0);
        $count = M('users')->where($where)->count();
        $user_list = M('users')->where($where)->select();
        $total = 0;
        if(!empty($user_list)){
            foreach ($user_list as $key=>$value){
                if($value['first_weight'] >$value['last_weight']){
                    $total += $value['first_weight']-$value['last_weight'];
                }
            }
        }
        $fund = $total*10;
        //更新token和公益基金
        M('system')->where('id', 1)->update(array('token' => $token_new,'fund'=>$fund));
        echo 'OK';
    }

}